<template>
  <div>
    <basic-dialog
      :visible.sync="visible"
      :handleClose="handleCloseDialog"
      :handleOpen="handleOpen"
      :title="title"
      :show-footer="false"
      :width="'60%'"
    >
      <BasicTable
        ref="basicTable"
        :showPagination="false"
        :showSelectCol="false"
        :loading="tableInfo.loading"
        :columns="tableInfo.columns"
        :dataSource="tableInfo.list"
        :tableHeight="443"
      />
    </basic-dialog>
  </div>
</template>
<script>
import BasicDialog from '@/components/BasicDialog';
import BasicTable from '@/components/supplier/BasicTable';
import {
  queryCloseLogsService
} from '@/api/supplier/management/supplierAccount';

export default {
  name: 'SelectSupplierDialog',
  components: {
    BasicDialog,
    BasicTable,
  },
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    viewId: {
      type: [Number, String],
    },
  },
  data () {
    return {
      title: '操作日志',
      tableInfo: {
        list: [],
        loading: false,
        columns: [
          {
            title: '序号',
            key: 'index',
            width: 55,
            render: (h, { row, index }) => {
              return <span>{ index + 1 }</span>
            }
          },
          {
            title: '供应商代码',
            key: 'supplierCode'
          },
          {
            title: '供应商名称',
            key: 'supplierName'
          },
          {
            title: '操作人',
            key: 'createUser'
          },
          {
            title: '操作时间',
            key: 'createTime'
          },
          {
            title: '操作说明',
            key: 'operationInstructionName'
          },
          {
            title: '关闭原因',
            key: 'closeReason'
          },
        ],
      }
    };
  },
  methods: {
    handleOpen () {
      this.handleQueryData()
    },
    // 获取 表格数据
    async handleQueryData () {
      const res = await queryCloseLogsService(
        { supplierId: this.viewId },
        state => { this.tableInfo.loading = state }
      )
      if (res) {
        const { result } = res
        this.tableInfo.list = result;
      }
    },
    // 关闭弹框
    handleCloseDialog () {
      this.$emit('update:visible', false);
    },
  }
};
</script>
